#ifndef __GRID_H__
#define __GRID_H__

#include <vector>
#include "parameter.h"
#include "vec.h"
#include "face.h"

class Cell
{
   public:
      unsigned int vertex[4];
};

class Vertex
{
   public:
      Vector coord;
      int    type;
      std::vector<unsigned int> nbr; // neigbouring vertices
      Vector normal; // only needed for boundary vertices
};

class Edge
{
   public:
      unsigned int n0;    // first  vertex of edge
      unsigned int n1;    // second vertex of edge
      Vector       coef0;
      Vector       coef1;
      int          type;
      Vector       normal; // for boundary condition
};

class Grid
{
   public:
      Grid () { n_vertex = n_cell = n_face = n_edge = n_boundary_face = 0; };
      unsigned int n_vertex;
      unsigned int n_cell;
      unsigned int n_face;
      unsigned int n_edge;
      unsigned int n_boundary_face;
      std::vector<Vertex> vertex;
      std::vector<Cell>   cell;
      std::vector<Face>   face;
      std::vector<Edge>   edge;

      void read (const Parameter& param);

   private:
      void read_gmsh (std::string grid_file);
      void check_face_type (const std::map<int,BoundaryCondition>& bc);
      void preproc ();
      void info ();
      void make_edges ();
      void compute_ls_coef ();
};

#endif
